/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TaskGUI.java
 *
 * Created on Jun 18, 2009, 8:49:26 AM
 */
package GUI;

import BUS.Task2BUS;
import DTO.Task2DTO;
import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author trquanglong
 */
public class TaskGUI extends javax.swing.JFrame {

    private int _selectedTask;
    private boolean bEditable = false;

    /** Creates new form TaskGUI */
    public TaskGUI() {
        initComponents();

        menuByList.setSelected(true);
        menuByCard.setSelected(false);
        ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
        lstTask = Task2BUS.getListTask();
        showTableTask(tableTask, lstTask, bEditable);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        tabTask = new javax.swing.JTabbedPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableTask = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        panelCard = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        bttnNew = new javax.swing.JButton();
        bttnEdit = new javax.swing.JButton();
        bttnDelete = new javax.swing.JButton();
        bttnByCard = new javax.swing.JButton();
        bttnByList = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        menuNew = new javax.swing.JMenuItem();
        menuExit = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        menuEdit = new javax.swing.JMenuItem();
        menuDelete = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        menuByList = new javax.swing.JCheckBoxMenuItem();
        menuByCard = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPanel1KeyReleased(evt);
            }
        });

        tabTask.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabTaskStateChanged(evt);
            }
        });

        tableTask.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane2.setViewportView(tableTask);

        tabTask.addTab("by List", jScrollPane2);

        panelCard.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                panelCardMouseReleased(evt);
            }
        });
        panelCard.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                panelCardKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                panelCardKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout panelCardLayout = new javax.swing.GroupLayout(panelCard);
        panelCard.setLayout(panelCardLayout);
        panelCardLayout.setHorizontalGroup(
            panelCardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1062, Short.MAX_VALUE)
        );
        panelCardLayout.setVerticalGroup(
            panelCardLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 531, Short.MAX_VALUE)
        );

        jScrollPane3.setViewportView(panelCard);

        tabTask.addTab("by Card", jScrollPane3);

        jToolBar1.setBorder(null);
        jToolBar1.setRollover(true);

        bttnNew.setIcon(new javax.swing.ImageIcon(getClass().getResource("/create_task.gif"))); // NOI18N
        bttnNew.setMnemonic('1');
        bttnNew.setText("New task");
        bttnNew.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bttnNew.setFocusable(false);
        bttnNew.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bttnNew.setMaximumSize(new java.awt.Dimension(65, 65));
        bttnNew.setMinimumSize(new java.awt.Dimension(60, 60));
        bttnNew.setPreferredSize(new java.awt.Dimension(80, 80));
        bttnNew.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        bttnNew.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bttnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnNewActionPerformed(evt);
            }
        });
        jToolBar1.add(bttnNew);

        bttnEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edit.png"))); // NOI18N
        bttnEdit.setMnemonic('1');
        bttnEdit.setText("Edit");
        bttnEdit.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bttnEdit.setFocusable(false);
        bttnEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bttnEdit.setMaximumSize(new java.awt.Dimension(65, 65));
        bttnEdit.setMinimumSize(new java.awt.Dimension(60, 60));
        bttnEdit.setPreferredSize(new java.awt.Dimension(80, 80));
        bttnEdit.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        bttnEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bttnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnEditActionPerformed(evt);
            }
        });
        jToolBar1.add(bttnEdit);

        bttnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/DeleteTask.png"))); // NOI18N
        bttnDelete.setMnemonic('1');
        bttnDelete.setText("Delete");
        bttnDelete.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bttnDelete.setFocusable(false);
        bttnDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bttnDelete.setMaximumSize(new java.awt.Dimension(65, 65));
        bttnDelete.setMinimumSize(new java.awt.Dimension(60, 60));
        bttnDelete.setPreferredSize(new java.awt.Dimension(80, 80));
        bttnDelete.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        bttnDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bttnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnDeleteActionPerformed(evt);
            }
        });
        jToolBar1.add(bttnDelete);

        bttnByCard.setIcon(new javax.swing.ImageIcon(getClass().getResource("/TaskCard.jpg"))); // NOI18N
        bttnByCard.setMnemonic('1');
        bttnByCard.setText("By Card");
        bttnByCard.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bttnByCard.setFocusable(false);
        bttnByCard.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bttnByCard.setMaximumSize(new java.awt.Dimension(65, 65));
        bttnByCard.setMinimumSize(new java.awt.Dimension(60, 60));
        bttnByCard.setPreferredSize(new java.awt.Dimension(80, 80));
        bttnByCard.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        bttnByCard.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bttnByCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnByCardActionPerformed(evt);
            }
        });
        jToolBar1.add(bttnByCard);

        bttnByList.setIcon(new javax.swing.ImageIcon(getClass().getResource("/task_list.gif"))); // NOI18N
        bttnByList.setMnemonic('1');
        bttnByList.setText("By List");
        bttnByList.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        bttnByList.setFocusable(false);
        bttnByList.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        bttnByList.setMaximumSize(new java.awt.Dimension(65, 65));
        bttnByList.setMinimumSize(new java.awt.Dimension(60, 60));
        bttnByList.setPreferredSize(new java.awt.Dimension(80, 80));
        bttnByList.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/Save.png"))); // NOI18N
        bttnByList.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        bttnByList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bttnByListActionPerformed(evt);
            }
        });
        jToolBar1.add(bttnByList);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 332, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(737, Short.MAX_VALUE))
            .addComponent(tabTask, javax.swing.GroupLayout.DEFAULT_SIZE, 1069, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tabTask, javax.swing.GroupLayout.DEFAULT_SIZE, 561, Short.MAX_VALUE))
        );

        jMenu1.setText("File");

        menuNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        menuNew.setText("New");
        menuNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuNewActionPerformed(evt);
            }
        });
        jMenu1.add(menuNew);

        menuExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        menuExit.setText("Exit");
        menuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuExitActionPerformed(evt);
            }
        });
        jMenu1.add(menuExit);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        menuEdit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        menuEdit.setText("Edit ");
        menuEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuEditActionPerformed(evt);
            }
        });
        jMenu2.add(menuEdit);

        menuDelete.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DELETE, 0));
        menuDelete.setText("Delete");
        menuDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuDeleteActionPerformed(evt);
            }
        });
        jMenu2.add(menuDelete);

        jMenuBar1.add(jMenu2);

        jMenu3.setText("View");
        jMenu3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu3ActionPerformed(evt);
            }
        });

        menuByList.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.ALT_MASK));
        menuByList.setSelected(true);
        menuByList.setText("by List");
        menuByList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuByListActionPerformed(evt);
            }
        });
        jMenu3.add(menuByList);

        menuByCard.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_2, java.awt.event.InputEvent.ALT_MASK));
        menuByCard.setSelected(true);
        menuByCard.setText("by Card");
        menuByCard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuByCardActionPerformed(evt);
            }
        });
        jMenu3.add(menuByCard);

        jMenuBar1.add(jMenu3);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * show list of tasks on table (editable = true or false)
     * @param tableTask
     * @param lstTask
     * @param bEditable
     */
    private void showTableTask(JTable tableTask, ArrayList<Task2DTO> lstTask, final boolean bEditable) {
        Vector rowHeader = new Vector();
        rowHeader.add("Subject");
        rowHeader.add("Start Day");
        rowHeader.add("End Day");
        rowHeader.add("Status");
        rowHeader.add("Priority");
        rowHeader.add("Complete");
        rowHeader.add("Ơwner");

        //DefaultTableModel model = new DefaultTableModel(rowHeader, 0);
        DefaultTableModel model = new DefaultTableModel(rowHeader, 0) {

            @Override
            public boolean isCellEditable(int row, int column) {
                return bEditable;
            }
        };
        tableTask.setModel(model);
        for (int i = 0; i < lstTask.size(); i++) {
            Vector rowData = new Vector();
            rowData.add(lstTask.get(i).getSubject());
            rowData.add(lstTask.get(i).getStartedDay());
            rowData.add(lstTask.get(i).getEndDay());
            rowData.add(lstTask.get(i).getStatus());
            rowData.add(lstTask.get(i).getPriority());
            rowData.add(lstTask.get(i).getComplete());
            rowData.add(lstTask.get(i).getOwner());
            model.addRow(rowData);
        }
        if (lstTask.size() != 0) {
            tableTask.setRowSelectionInterval(0, 0);
        }
    }

    private void showCardTask(JPanel panelTask, ArrayList<Task2DTO> lstTask, int index) {
        panelTask.removeAll();
        panelTask.repaint();
        panelTask.setLayout(new java.awt.GridLayout(0, 3, 20, 20));
        for (int i = 0; i < lstTask.size(); i++) {
            InternalTaskFrame myFrame = new InternalTaskFrame(lstTask.get(i));
            if (i == index) {
                myFrame.setBackground(Color.RED);
            }
            panelTask.add(myFrame);
            myFrame.setVisible(true);
        }
        _selectedTask = 0;
    }

    private void bttnByListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnByListActionPerformed
        // TODO add your handling code here:
        menuByListActionPerformed(evt);
}//GEN-LAST:event_bttnByListActionPerformed

    private void bttnByCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnByCardActionPerformed
        // TODO add your handling code here:
        menuByCardActionPerformed(evt);
}//GEN-LAST:event_bttnByCardActionPerformed

    /**
     * Edit one task from list
     * Edit informations of Task
     * @param evt
     */
    private void bttnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnEditActionPerformed

        if (menuByList.isSelected()) {
            if (tableTask.getModel().isCellEditable(0, 0) == false) {//Click button Edit
                ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
                lstTask = Task2BUS.getListTask();
                bEditable = true;
                showTableTask(tableTask, lstTask, bEditable);
                bttnEdit.setText("Update");
            } //if (tableTask.getModel().isCellEditable(0, 0) == true) { //Click button Update
            else {
                ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
                for (int i = 0; i < tableTask.getRowCount(); i++) {
                    Task2DTO task = new Task2DTO();
                    String subject = tableTask.getModel().getValueAt(i, 0).toString();
                    if (subject != null) {
                        task.setSubject(subject);
                    } else {
                        task.setSubject("");
                    }

                    String start = (String) tableTask.getValueAt(i, 1);
                    if (start != null) {
                        task.setStartedDay(start);
                    } else {
                        task.setStartedDay("");
                    }

                    String end = (String) tableTask.getValueAt(i, 2);
                    if (end != null) {
                        task.setEndDay(end);
                    } else {
                        task.setEndDay("");
                    }

                    String status = (String) tableTask.getValueAt(i, 3);
                    if (status != null) {
                        task.setStatus(status);
                    } else {
                        task.setStatus("");
                    }

                    String priority = (String) tableTask.getValueAt(i, 4);
                    if (priority != null) {
                        task.setPriority(priority);
                    } else {
                        task.setPriority("");
                    }

                    Object tamp = tableTask.getValueAt(i, 5);
                    String complete = tamp.toString();
                    task.setComplete(Integer.parseInt(complete));


                    String owner = (String) tableTask.getValueAt(i, 6);
                    if (owner != null) {
                        task.setOwner(owner);
                    } else {
                        task.setOwner("");
                    }
                    lstTask.add(task);
                }
                bttnEdit.setText("Edit");
                Task2BUS.updateAllTask(lstTask);
                bEditable = false;
                showTableTask(tableTask, lstTask, bEditable);

            }
        }

}//GEN-LAST:event_bttnEditActionPerformed

    /**
     * Delete one task from list
     * @param evt
     */
    private void bttnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnDeleteActionPerformed
        // TODO add your handling code here:
        int option = JOptionPane.showConfirmDialog(null, "Do you want to delete this task?", "Confirm Delete", JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
            if (menuByList.isSelected()) {
                ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
                lstTask = Task2BUS.getListTask();
                if (lstTask.size() > 0) {
                    Task2BUS.deleteOneTask(lstTask.get(tableTask.getSelectedRow()));
                    lstTask = Task2BUS.getListTask();
                    showTableTask(tableTask, lstTask, bEditable);
                }
            }
        }
}//GEN-LAST:event_bttnDeleteActionPerformed

    private void bttnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnNewActionPerformed
        // TODO add your handling code here:
        NewTaskGUI newTaskForm = new NewTaskGUI(this, rootPaneCheckingEnabled);
        newTaskForm.show();
        if (newTaskForm.isChange()) {
            if (menuByList.isSelected()) {
                ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
                lstTask = Task2BUS.getListTask();
                showTableTask(tableTask, lstTask, false);
            }
        }
}//GEN-LAST:event_bttnNewActionPerformed

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu3ActionPerformed

    private void menuByListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuByListActionPerformed
        // TODO add your handling code here:
        menuByList.setSelected(true);
        menuByCard.setSelected(false);
        tabTask.setSelectedIndex(0);
        ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
        lstTask = Task2BUS.getListTask();
        showTableTask(tableTask, lstTask, false);
}//GEN-LAST:event_menuByListActionPerformed

    /**
     * Edit informations of Task
     * @param evt
     */
    private void menuEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuEditActionPerformed
        // TODO add your handling code here:
        bttnEditActionPerformed(evt);
    }//GEN-LAST:event_menuEditActionPerformed

    private void menuDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuDeleteActionPerformed
        // TODO add your handling code here:
        bttnDeleteActionPerformed(evt);
    }//GEN-LAST:event_menuDeleteActionPerformed

    private void menuNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNewActionPerformed
        // TODO add your handling code here:
        bttnNewActionPerformed(evt);
    }//GEN-LAST:event_menuNewActionPerformed

    private void menuByCardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuByCardActionPerformed
        // TODO add your handling code here:
        menuByList.setSelected(false);
        menuByCard.setSelected(true);
        tabTask.setSelectedIndex(1);
        ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
        lstTask = Task2BUS.getListTask();
        showCardTask(panelCard, lstTask, 0);

    }//GEN-LAST:event_menuByCardActionPerformed

    private void tabTaskStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabTaskStateChanged
        // TODO add your handling code here:
        java.awt.event.ActionEvent tmpEvt = null;
        if (tabTask.getSelectedIndex() == 0) {//tab List
            menuByListActionPerformed(tmpEvt);
        } else {
            menuByCardActionPerformed(tmpEvt);
        }
    }//GEN-LAST:event_tabTaskStateChanged

    private void panelCardMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_panelCardMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_panelCardMouseReleased

    private void panelCardKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_panelCardKeyReleased
        // TODO add your handling code here:
        ArrayList<Task2DTO> lstTask = new ArrayList<Task2DTO>();
        lstTask = Task2BUS.getListTask();
        if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            if (_selectedTask < lstTask.size() - 3) {
                _selectedTask += 3;
            } else {
                _selectedTask = lstTask.size() - 1;
            }
        }

        if (evt.getKeyCode() == KeyEvent.VK_UP) {
            if (_selectedTask >= 3) {
                _selectedTask -= 3;
            } else {
                _selectedTask = 0;
            }
        }

        if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
            if (_selectedTask >= 1) {
                _selectedTask -= 1;
            } else {
                _selectedTask = 0;
            }
        }
        if (evt.getKeyCode() == KeyEvent.VK_RIGHT) {
            if (_selectedTask < lstTask.size() - 1) {
                _selectedTask += 1;
            } else {
                _selectedTask = lstTask.size() - 1;
            }
        }

        showCardTask(panelCard, lstTask, _selectedTask);

    }//GEN-LAST:event_panelCardKeyReleased

    private void jPanel1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyReleased
        // TODO add your handling code here:
        if (menuByCard.isSelected()) {
            panelCardKeyReleased(evt);
        }
    }//GEN-LAST:event_jPanel1KeyReleased

    private void panelCardKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_panelCardKeyPressed
        // TODO add your handling code here:
        if (menuByCard.isSelected()) {
            panelCardKeyReleased(evt);
        }
    }//GEN-LAST:event_panelCardKeyPressed

    private void menuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuExitActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_menuExitActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new TaskGUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bttnByCard;
    private javax.swing.JButton bttnByList;
    private javax.swing.JButton bttnDelete;
    private javax.swing.JButton bttnEdit;
    private javax.swing.JButton bttnNew;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JCheckBoxMenuItem menuByCard;
    private javax.swing.JCheckBoxMenuItem menuByList;
    private javax.swing.JMenuItem menuDelete;
    private javax.swing.JMenuItem menuEdit;
    private javax.swing.JMenuItem menuExit;
    private javax.swing.JMenuItem menuNew;
    private javax.swing.JPanel panelCard;
    private javax.swing.JTabbedPane tabTask;
    private javax.swing.JTable tableTask;
    // End of variables declaration//GEN-END:variables
}
